<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 分糖果 -->
    <script>
      function res(ratings) {
        let count = new Array(ratings.length).fill(1)
        for (let i = 1; i < ratings.length; i++) {
          if (ratings[i] > ratings[i - 1]) {
            count[i] = count[i - 1] + 1
          }
        }
        for (let i = ratings.length - 2; i >= 0; i--) {
          if (ratings[i] > ratings[i + 1]) {
            count[i] = Math.max(count[i], count[i + 1] + 1)
          }
        }
        let sum = count.reduce((total, item) => {
          return total + item
        })
        return sum
      }
      console.log(res([1, 0, 2]))
    </script>
  </body>
</html>
